<template>
  <header class="header">
    <h1>todos</h1>
    <input id="toggle-all" class="toggle-all" type="checkbox" >
    <label for="toggle-all"></label>
    <input
    v-model="newtodo"
      class="new-todo"
      placeholder="输入任务名称-回车确认"
      autofocus
      @keyup.enter="addTodo"
    />
  </header>
</template>

<script>
import { mapGetters } from 'vuex';
export default {
  data() {
    return {
      newtodo:''
    }
  },
  computed:{
    ...mapGetters(['TodoMain'])
  },
  methods:{
    addTodo(){
      if(this.newtodo.trim() != ''){
        const data = {
          id: this.TodoMain.length ? this.TodoMain[0].id + 1 : 1,
        done: false,
        value:this.newtodo
        }
        this.List = this.TodoMain
        this.List.unshift(data)
        this.$store.commit('TodoMain/setTodoMainList',this.List)
      }else{
        alert('请输入文件名!')
      }
      this.newtodo = ''
    } 
  },
  
}
</script>
